//
//  HMNavigationController.swift
//  swift-新浪微博0
//
//  Created by 赵玉忠 on 16/8/29.
//  Copyright © 2016年 itcast. All rights reserved.
//

import UIKit

class HMNavigationController: UINavigationController {

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
    }
    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        
        // 判断，当前push进来的不是第1个控制器
        // 大于0代表已经有一个控制器，
        if childViewControllers.count > 0 {
            
            var title = "返回"
            
            if childViewControllers.count == 1 {
                // title 要取 first vc 的title
                title = childViewControllers.first?.title ?? "返回"
            }
            
            viewController.navigationItem.leftBarButtonItem = UIBarButtonItem(imgName: "navigationbar_back_withtext", title: title, target: self, action: #selector(back))
            // 在push出来的时候隐藏底部的tabBar
            viewController.hidesBottomBarWhenPushed = true;
        }
        super.pushViewController(viewController, animated: true)
    }
    func back()  {
        _ = popViewController(animated: true)
    }
}
